package com.jiangore.client;

import com.alibaba.fastjson.JSONObject;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

import javax.xml.namespace.QName;

/**
 * @Todo
 * @Author jiangtao
 * @CreateBy 2020-03-14 10:46 PM
 * @UpdateBy jiangtao
 * @Version v1.0
 */
public class CXFClientTest {

    //webService接口地址
    private static String address = "http://localhost:8080/ws/hello?wsdl";

    private static String token = "abc123";

    public static void main(String[] args) throws Exception {
        JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
        Client client = factory.createClient(address);

        //登录拦截器
        client.getOutInterceptors().add(new ClientLoginInterceptor(token));

        QName qName = new QName("http://ws.jiangore.com/", "helloWebServices");
        Object[] result = client.invoke(qName, new Object[] {"world!"});

        System.out.println(JSONObject.toJSONString(result));

    }
}
